package cn.com.dhcc.adam.spring.mvc.three;

import java.io.Writer;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping(value = "/req")
public class RequestBodyController {

	@RequestMapping(value = "/requestM")
	public String handler(@RequestBody String body, Writer writer) {
		System.out.println(body);
		return "helloworld";
	}

	@RequestMapping(value = "/helloWorld")
	public String helloWorld(Model model) {
		model.addAttribute("message", "Hello World!");
		System.out.println("执行helloword方法");
		return "helloworld";
	}

	@RequestMapping(value = "/baidu")
	public String rBaidu() {
		System.out.println("执行跳转到百度方法");
		return "redirect:http://baidu.com";
	}

	@ModelAttribute
	public void populateModel(@RequestParam(required = false) String number) {
		System.out.println("执行带有@ModelAttribute方法: number = " + number);
	}

	@ModelAttribute("name")
	public String addAccount() {
		System.out.println("执行@ModelAttribute(\"name\")方法");
		return "this is a 测试:名称";
	}

	@RequestMapping(value = "/mapa")
	public String modelAttrParam(@ModelAttribute("name") String name) {
		System.out.println("in /mapa , name = " + name);
		return "helloworld";
	}
	
	@RequestMapping(value = "/rb",method = RequestMethod.GET)
	public String rb(Model model) {
		model.addAttribute("message", "Hello Spring MVC Framework!");
		System.out.println("执行helloword方法");
		return "requestBody";
	}
}
